<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/inc/incSession.jsp" %>
<jsp:include page="/common/inc/Top.jsp" />
<%
	String dong 	= util.getStr(request.getParameter("dong"));
	
	// paging
	String perRow 		= util.getStr(request.getParameter("perRow"));
	String startRow 	= util.getStr(request.getParameter("startRow"));
	String currentPage 	= util.getStr(request.getParameter("currentPage"));
	
	perRow = "".equals(perRow) ?"10":perRow;
	startRow = "".equals(startRow)?"0":startRow;
	currentPage = "".equals(currentPage)?"1":currentPage;
	
	param.put("dong",dong);
	
	// paging
	param.put("perRow", perRow);
	param.put("startRow", startRow);
	
%>
<script type="text/javascript">
	
	$(document).ready(function() {
		
//		초기값 셋팅
		$("#dong").val("<%=dong%>");
		$("#currentPage").val("<%=currentPage%>");
		$("#startRow").val("<%=startRow%>");
		
//		검색
		$("#btnSearch").click(function() {
			$("#zip").attr("action","/common/zipcode/postSearch.jsp");
			$("#zip").attr("target","_self");		
			$("#zip").submit();
			
		});
		
		//	초기화
		$("#btnReset").click(function() {
			
			$("input[type=text]").val("");
			
		});

		//	검색
		jQuery("a[name^='goPage']").click(function(){
						
			$("#startRow").val($(this).attr("startRow"));
			$("#currentPage").val($(this).attr("currentPage"));
			$("#zip").attr("action","/common/zipcode/postSearch.jsp");
			$("#zip").attr("target","_self");		
			$("#zip").submit();
			
		});
		
		$("#zip").validate({
			rules: {
				dong : "required"
			},
				
		  messages: {
			  dong : "동이름을 입력해주세요"
		  }
		});
});
	
	function copy(a,b,c,d,e)
	{		
		opener.form.zipcode.value = e;
		opener.form.addr1.value = a+' '+b+' '+c+' '+d;
		opener.form.addr2.focus();
		window.close();
	}
	
	

</script>
<body>

<form id="zip" name="zip" method="post">

<input type="hidden" name="currentPage" id="currentPage" value="" />
<input type="hidden" name="startRow" id="startRow" value="" />

<input name="dong" id="dong" value="" size="30">
<div class=" al_center ">
	<button type="submit" id="btnSearch">조회</button>
</div>
<table border="1">
	<tr><td>우편번호</td><td>지역명</td></tr>
<%
	if(dong!=""){
		ArrayList rs =	(ArrayList)sqlMap.queryForList("Common.selectZipCode",param);	//	실행할 SQL ID, 검색조건(없을경우 null)
		HashMap map	 = 	(HashMap)sqlMap.queryForObject("Common.selectZipCodeTotal",param);	//	실행할 SQL ID, 검색조건(없을경우 null)
	
		for( int i = 0 ; i < rs.size() ; i++){
%>
    <tr>
    <td><%= util.getStr(((HashMap)rs.get(i)).get("zipcode")) %></td>
    <td>
    <a href="#" onclick="copy('<%= util.getStr(((HashMap)rs.get(i)).get("sido")) %>',
                              '<%= util.getStr(((HashMap)rs.get(i)).get("gugun"))%>',
                              '<%= util.getStr(((HashMap)rs.get(i)).get("dong"))%>',
                              '<%= util.getStr(((HashMap)rs.get(i)).get("bunji")) %>',
                              '<%= util.getStr(((HashMap)rs.get(i)).get("zipcode")) %>')">
    <%= util.getStr(((HashMap)rs.get(i)).get("sido")) %>
    <%= util.getStr(((HashMap)rs.get(i)).get("gugun"))%>
    <%= util.getStr(((HashMap)rs.get(i)).get("dong"))%>
    <%= util.getStr(((HashMap)rs.get(i)).get("bunji")) %></a>
    </td>
    </tr>
<%		
		}
%>	
</table>
<%@ include file="/common/inc/paging.jsp" %>
<%	
	}
%>

</form>



</body>
</html>